package com.wxy.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wxy.web.model.Role;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author wxy
 * @since 2021-06-13
 */
public interface RoleMapper extends BaseMapper<Role> {

    @Select("insert into role_permission (role_id,permission_id)values('${roleId}','${permissionId}')")
    Integer insertRolePermission(@Param("roleId") Integer roleId,@Param("permissionId") Integer permissionId);

    @Select("delete from role_permission where role_id = '${roleId}'")
    Integer deleteRolePermissionByRoleId(@Param("roleId") Integer roleId);

    @Select("delete from user_role where role_id = ${roleId} and user_id=${userId}")
    Integer deleteRoleUser(@Param("roleId") Integer roleId,@Param("userId") Integer userId);

    @Select("select ur.role_id from user_role ur where user_id=${userId}")
    List<Integer> listRoleIdsByUserId(@Param("userId") Integer userId);
}
